@echo off setlocal @REM This script is originally from: @REM http://blogs.msdn.com/adioltean/archive/2005/01/05/346793.aspx @REM test if we are called by VSHADOW if NOT "%CALLBACK_SCRIPT%"=="" goto :IS_CALLBACK @REM @REM Get the source and destination path @REM set SOURCE_DRIVE_LETTER=%~d1 set SOURCE_RELATIVE_PATH=%~pnx1 set DESTINATION_PATH=%2 @REM @REM Create the shadow copy - and generate env variables into a temporary script. @REM @REM Then, while the shadow is still live @REM recursively execute the same script. @REM @echo ...Determine the scripts to be executed/generated... set CALLBACK_SCRIPT=%~dpnx0 set TEMP_GENERATED_SCRIPT=GeneratedVarsTempScript.cmd @echo ...Creating the shadow copy... "%~dp0\vshadow.exe" -script="%TEMP_GENERATED_SCRIPT%" -exec="%CALLBACK_SCRIPT%" %SOURCE_DRIVE_LETTER% del /f "%TEMP_GENERATED_SCRIPT%" @goto :EOF :IS_CALLBACK setlocal @REM @REM This generated script should set the SHADOW_DEVICE_1 env variable @REM @echo ...Obtaining the shadow copy device name... call "%TEMP_GENERATED_SCRIPT%" @REM @REM This should copy the file to the right location @REM @echo ...Copying from the shadow copy to the destination path... copy "%SHADOW_DEVICE_1%\%SOURCE_RELATIVE_PATH%" %DESTINATION_PATH%